﻿@using KPIS.GERP.SERVICE.Model
@model hrm_ps_command_dtls

@{
    ViewBag.Title = "คำสั่งบรรจุ";
    GERPContext db = new GERPContext();
    var CommandModel = db.hrm_ps_commands.Find(Model.cmd_seq);
    int empTypeSeq = 0;
    if (CommandModel != null && CommandModel.emp_type_seq != null)
    {
        empTypeSeq = CommandModel.emp_type_seq.Value;
    }
}

@using (Html.BeginForm())
{
    @*@Html.AntiForgeryToken()*@
    @Html.ValidationSummary(true)
    <h3 class="header"><span class="red">แก้ไข</span> รายชื่อในคำสั่ง</h3>
    <div class="detail">
        <h3><label id="lblCmdTypeName"></label></h3>
        @Html.HiddenFor(model => model.cmd_seq)
        @Html.HiddenFor(model => model.cmd_dtls_seq)

        <table class="info">
            <tr class="left2">
                <td class="editor-label">
                    @Html.LabelFor(model => model.emp_seq)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.emp_seq)
                        .BindTo(new SelectList(new GERPContext().hrm_ps_employees
                            .Where(m => m.record_status != "D" && m.hrm_ps_employee_statuses != null && m.hrm_ps_employee_statuses.active == "1" &&  m.emp_type_seq == empTypeSeq)
                            .OrderBy(m => m.first_name)
                            .ToList(), "emp_seq", "full_name"))
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                        .ClientEvents(client => client.OnChange("ddlEmpChange"))
                    )
                    @Html.ValidationMessageFor(model => model.emp_seq)
                </td>
            </tr>
            <tr class="left">
                <td class="editor-label">
                    @Html.LabelFor(model => model.start_date)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.start_date)
                    @Html.ValidationMessageFor(model => model.start_date)
                </td>
            </tr>
            <tr class="left">
                <td class="editor-label">
                    @Html.LabelFor(model => model.remarks)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.remarks)
                    @Html.ValidationMessageFor(model => model.remarks)
                </td>
            </tr>
            <tr class="left2">
                <td class="editor-label">
                    @Html.LabelFor(model => model.rpt_remarks)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.rpt_remarks)
                    @Html.ValidationMessageFor(model => model.rpt_remarks)
                </td>
            </tr>
        </table>
        <table class="info">
            <tr>
                <th>

                </th>
                <th colspan="1">
                    ข้อมูลเดิม
                </th>
                <th colspan="1">
                    ข้อมูลใหม่
                </th>
            </tr>
            <tr>
                <td class="editor-label" width="150px">
                    ตำแหน่ง
                </td>
                <td class="editor-field" width="300px">
                    @Html.HiddenFor(model => model.old_pos_seq)
                    @Html.TextBoxFor(model => model.old_pos_ref, new { @readonly="readonly", style="width:50px;" }) : 
                    @Html.TextBoxFor(model => model.old_pos_name, new { @readonly="readonly", style="width:150px;" } )
                    @Html.ValidationMessageFor(model => model.old_pos_seq)
                </td>
                <td class="editor-field" width="300px">
                    @(Html.Telerik().ComboBoxFor(m => m.new_pos_seq)
                        .BindTo(new SelectList(new GERPContext().hrm_mp_positions
                            .Where(m => m.record_status != "D" && m.emp_type_seq == CommandModel.emp_type_seq)
                            .ToList().OrderBy(m => m.pos_ref.AsInt(0)), "pos_seq", "pos_text"))
                        //.SelectedIndex(Model != null ? (Model.emp_type_seq != null ? Model.emp_type_seq.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                        .ClientEvents(client => client.OnChange("ddlNewPosChange"))
                    )
                    <br/>@Html.HiddenFor(m => m.new_pos_ref)
                    @Html.HiddenFor(m => m.new_pos_name)
                        
                    @Html.ValidationMessageFor(model => model.new_pos_seq)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    ระดับ
                </td>
                <td class="editor-field">
                    @Html.HiddenFor(model => model.old_class_seq)
                    @Html.TextBoxFor(model => model.old_hrm_mp_classes.class_name, new { @readonly="readonly" })
                    @Html.ValidationMessageFor(model => model.old_class_seq)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.new_class_seq)
                        .BindTo(new SelectList(new GERPContext().hrm_mp_classes
                            .Where(m => m.record_status != "D" && m.emp_type_seq == CommandModel.emp_type_seq)
                            .ToList(), "class_seq", "class_name"))
                        //.SelectedIndex(Model != null ? (Model.emp_type_seq != null ? Model.emp_type_seq.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                        //.ClientEvents(client => client.OnChange("ddlNewClassChange"))
                    )
                        
                    @Html.ValidationMessageFor(model => model.new_class_seq)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    ตำแหน่งบริหาร
                </td>
                <td class="editor-field">
                    @Html.HiddenFor(model => model.old_exec_pos_seq)
                    @Html.TextBoxFor(model => model.old_exec_pos_name, new { @readonly="readonly" })
                    @Html.ValidationMessageFor(model => model.old_exec_pos_name)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.new_exec_pos_seq)
                        .BindTo(new SelectList(new GERPContext().hrm_mp_exec_positions
                            .Where(m => m.record_status != "D")
                            .Distinct()
                            .ToList(), "exec_pos_name", "exec_pos_name"))
                        //.SelectedIndex(Model != null ? (Model.emp_type_seq != null ? Model.emp_type_seq.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                        .ClientEvents(client => client.OnChange("ddlNewExecChange"))
                    )
                    <br/>@Html.HiddenFor(m => m.new_exec_pos_name)
                        
                    @Html.ValidationMessageFor(model => model.new_exec_pos_seq)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    สังกัด
                </td>
                <td class="editor-field">
                    @Html.HiddenFor(model => model.old_job_site_seq)
                    @Html.TextBoxFor(model => model.old_job_site_name, new { @readonly="readonly" })
                    @Html.ValidationMessageFor(model => model.old_job_site_seq)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.new_job_site_seq)
                        .BindTo(new SelectList(new GERPContext().hrm_mp_job_sites
                            .Where(m => m.record_status != "D" && m.job_site_type_seq == 1)
                            .OrderBy(m => m.job_site_name)
                            .ToList(), "job_site_seq", "job_site_name"))
                        //.SelectedIndex(Model != null ? (Model.emp_type_seq != null ? Model.emp_type_seq.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                        .ClientEvents(client => client.OnChange("ddlNewJobSiteChange"))
                    )
                    <br/>@Html.HiddenFor(m => m.new_job_site_name)
                        
                    @Html.ValidationMessageFor(model => model.new_job_site_seq)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    สังกัดที่ปฏิบัติงาน
                </td>
                <td class="editor-field">
                    @Html.HiddenFor(model => model.old_working_job_site_seq)
                    @Html.TextBoxFor(model => model.old_working_job_site_name, new { @readonly="readonly" })
                    @Html.ValidationMessageFor(model => model.old_working_job_site_seq)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.new_working_job_site_seq)
                        .BindTo(new SelectList(new GERPContext().hrm_mp_job_sites
                            .Where(m => m.record_status != "D" && m.job_site_type_seq == 2)
                            .OrderBy(m => m.job_site_name)
                            .ToList(), "job_site_seq", "job_site_name"))
                        //.SelectedIndex(Model != null ? (Model.emp_type_seq != null ? Model.emp_type_seq.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                        .ClientEvents(client => client.OnChange("ddlNewWorkingJobSiteChange"))
                    )
                    <br/>@Html.HiddenFor(m => m.new_working_job_site_name)
                    @*<label id="lblNewWorkingJobSiteName" />*@
                        
                    @Html.ValidationMessageFor(model => model.new_working_job_site_seq)
                </td>
            </tr>
            <tr hidden visible="false">
                <td class="editor-label">
                    เงินเดือน
                </td>
                <td class="editor-field">
                    @Html.TextBoxFor(model => model.old_salary, new { @readonly="readonly" })
                    @Html.ValidationMessageFor(model => model.old_salary)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(m=> m.new_salary) บาท
                    @Html.ValidationMessageFor(model => model.new_job_site_seq)
                </td>
            </tr>
        </table>            
    
        <p id="pnlCommand2">
            <input type="submit" value="บันทึก" />&nbsp;&nbsp;
            @Html.ActionLink("ยกเลิกการแก้ไข", "Edit", new { id = Model.cmd_seq })
        </p>
    </div>
}

@section Scripts {
    <script type="text/javascript" >
        jQuery(function ($) {
            $("input#approved_type").change(function () {
                $("#divApproverInternal").toggle(this.value == "1");
                $("#divApproverExternal").toggle(this.value == "2");
            });
            $("input#approved_type:checked").change();
        });

        function ddlPenaltyChange(e) {
            var comboBox = $("#penalty_seq").data("tComboBox");
            $("[id^='lblCmdTypeName']").text('โทษ>' + comboBox.text());
        }

        function ddlEmpChange(e) {
            $.getJSON('@Url.Action("GetEmployeeForCommandDetail", "Employee")', { 'id': e.value }, function (data) {
                $("#old_pos_seq").val(data.pos_seq);
                $("#old_pos_ref").val(data.pos_ref);
                $("#old_pos_name").val(data.pos_name);
                $("#old_class_seq").val(data.class_seq);
                $("#old_hrm_mp_classes_class_name").val(data.class_name);
                $("#old_exec_name").val(data.exec_name);
                $("#old_job_site_seq").val(data.job_site_seq);
                $("#old_job_site_name").val(data.job_site_name);
                $("#old_working_job_site_seq").val(data.working_job_site_seq);
                $("#old_working_job_site_name").val(data.working_job_site_name);
                $("#old_salary").val(data.salary);
            });
        }

        function ddlNewPosChange(e) {
            var ddl = $("#new_pos_seq-input").val().split(" : ");
            $("#new_pos_ref").val(ddl[0]);
            $("#new_pos_name").val(ddl[1]);
        }
        //function ddlNewClassChange(e) {

        //    $("#new_class_name").val($("#new_class_seq-input").val());
        //}
        function ddlNewExecChange(e) {
            $("#new_exec_name").val($("#new_exec_name-input").val());
        }
        function ddlNewJobSiteChange(e) {
            $("#new_job_site_name").val($("#new_job_site_seq-input").val());
        }
        function ddlNewWorkingJobSiteChange(e) {
            $("#new_working_job_site_name").val($("#new_working_job_site_seq-input").val());
        }

        jQuery(function ($) {
            $("[type='submit']").click(function () {
                var ans = confirm("ต้องการบันทึก ใช่หรือไม่?");

                if (!ans) return false;
            });
        })

        jQuery(function ($) {
            $(".datepicker").datepicker({
                showOn: "focus",
            });
        });

        jQuery(function ($) {
            $("table.tablesorter").tablesorter({ widthFixed: true, sortList: [[0, 0]], widgets: ["zebra", "filter"] });
            //.tablesorterPager({ container: $("#pager"), size: $(".pagesize option:selected").val() });
        });
    </script>
}